import { constants } from './constants'
import { urls } from '@/api/urls'

const common = {
	install: function(Vue) {
		Vue.prototype.$common = this
	},
	
	onBack(n = 1) {
		uni.navigateBack({
			delta: n
		})
	},
	
	openUrl(url) {
		uni.navigateTo({
			url
		})
	},
	
	// px => rpx
	px2rpx(px) {
		const system = uni.getSystemInfoSync()
		return px / system.windowWidth * 750
	},
	
	confirm(title, content) {
		return new Promise((resolve, reject) => {
			uni.showModal({
				title,
				content,
				asyncClose: true,
				success: function (res) {
					if (res.confirm) {
						resolve()
					} else if (res.cancel) {
						reject()
					}
				}
			})
		})
	},
	
	// 判断当前页面是否有上级
	hasPageLevel() {
		const pages = getCurrentPages()
		return pages.length > 1
	},
}

export default common